﻿using System;
using WorkOrder.Business;
using System.Drawing;

namespace WorkOrder
{
    public partial class addUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windohref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.parent.location.href='../login.aspx';</script>");
            } 
            if (Page.IsPostBack)
            {
                //参数a的值的意义：0保存
                if (Request.Params["a"] == "0")
                {
                    if (!new Business_Table_Permission().HasInsert(Session["UserID"].ToString(), "Table_User"))
                    {
                        lblMsg.ForeColor = Color.Red;
                        lblMsg.Text = "提示信息：您没有新增用户的权限！";
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您没有新增用户的权限！');window.close();</script>");
                        return;
                    }
                    if (new Business_Table_User().AddUser(Server.HtmlEncode(txtLoginName.Text.Trim()), Server.HtmlEncode(txtPwd.Text.Trim()), Server.HtmlEncode(txtName.Text.Trim()), ridUser.Checked ? 0 : 1, chkOrder.Checked, chkChangeover.Checked, chkMaint.Checked, chkNotice.Checked))
                    {
                        txtName.Text = "";
                        txtLoginName.Text = "";
                        txtPwd.Text = "";
                        ridUser.Checked = true;
                        chkMaint.Checked = false;
                        chkChangeover.Checked = false;
                        chkOrder.Checked = false;
                        lblMsg.ForeColor = Color.DarkGreen;
                        lblMsg.Text = "提示信息：成功保存一条记录！";
                    }
                    else
                    {
                        lblMsg.ForeColor = Color.Red;
                        lblMsg.Text = "提示信息：保存记录失败！";
                    }
                }
            }
        }
    }
}
